console.log("欢迎来到活图网登录页面")
function user_login()
 {
    // 创建XMLHttpRequest对象
    xmlhttp = new XMLHttpRequest();

    // 设置同步模式请求
    xmlhttp.open("POST","http://127.0.0.1:80/login/",false);
    //这行代码很关键，用来把字符串类型的参数序列化成Form Data
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	// 设置回调函数
    xmlhttp.onreadystatechange = function() {

        if(xmlhttp.status==200){
            data = JSON.parse(xmlhttp.response)
            token = data["token"]
            //在前端存储token
            localStorage.setItem("token",token);
            localStorage.setItem("user",document.getElementById("userid").value);
            console.log(localStorage)
            code = JSON.parse(xmlhttp.response)["code"]
            if(code==100){
                location.href = "http://127.0.0.1:80/upimg/";
            }
            else if (code==700){
                alert("账号或者密码错误");
            }
            else{
                document.getElementById("userid_error").innerHTML=data.userid[0];
                document.getElementById("passwd_error").innerHTML=data.passwd[0];
            }
            //跳转到index.html
//            customHeader(token)

        }

    }
    xmlhttp.send("userid="+document.getElementById("userid").value+
                "&passwd="+document.getElementById("passwd").value
    );
 }


function customHeader(token) {
//    var client = new XMLHttpRequest();
//    client.open("GET", "http://127.0.0.1:80/upimg/");
//    client.setRequestHeader("Content-type","application/x-www-form-urlencoded");
//	client.setRequestHeader("token",token);

    window.location.href = "http://127.0.0.1:80/redirectpage/?=upimg";
}
function to_register(){
    window.location.href="http://127.0.0.1:80/register/";
 }

